-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow submitting empty data for related fields that are not required #36
base: master
Are you sure you want to change the base?
Conversation
content_type='application/json' | ||
) | ||
content = json.loads(response.content.decode()) | ||
self.assertEqual(content['bar'], {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently the response from the api will return the key with an empty object, but maybe we don't want to have a non-required related field in the response at all if it doesn't exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the field is there on the model. It seems to me we should be returning null if the gfk/fk is null and empty list if there are no m2ms.
|
||
content_object = content['content_object'] | ||
self.assertEqual(content_object['id'], bar.id) | ||
self.assertEqual(content_object['name'], bar.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test will fail until #35 if merged in
…into fk-empty-fields Conflicts: conduit/test/test_resources.py
Currently working on a complete fix for this. Taking me a while to get back into the problem. |
If you have a related field that is not required and you don't submit that field in your data, you get a
KeyError
when Conduit tries to save the related object.A request to a Conduit endpoint with an empty object for a FK creates an object with empty attributes and adds a
resource_uri
attribute that points to the list endpoint for the resource:This change prevents creating a FK if no data is submitted in the request. If you omit data for a non-required FK field in your request data, then the response will return an empty object in the response: